package com.example.smart_city_0829.activity.waimaidingcan;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.waimai.OrderDetail;
import com.example.smart_city_0829.entity.waimai.OrderList;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;

import retrofit2.Call;
import retrofit2.Response;

public class OrderDetailActivity extends BaseActivity {

    private ImageView im;
    private TextView name;
    private RatingBar star;
    private TextView tag1;
    private TextView tag2;
    private TextView tag3;
    private TextView tag4;
    private TextView tag5;



    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_detail;
    }

    @Override
    protected void initView() {
        im = (ImageView) findViewById(R.id.im);
        name = (TextView) findViewById(R.id.name);
        star = (RatingBar) findViewById(R.id.star);
        tag1 = (TextView) findViewById(R.id.tag1);
        tag2 = (TextView) findViewById(R.id.tag2);
        tag3 = (TextView) findViewById(R.id.tag3);
        tag4 = (TextView) findViewById(R.id.tag4);
        tag5 = (TextView) findViewById(R.id.tag5);
    }

    @Override
    protected void initData() {
//        String data = getIntent().getStringExtra("data");
//        OrderList.RowsBean rowsBean = gson.fromJson(data, OrderList.RowsBean.class);

        int id = getIntent().getIntExtra("id", 0);

        api.getOrderDetail(id).enqueue(new NetCallBack<OrderDetail>() {
            @Override
            public void onResponse(Call<OrderDetail> call, Response<OrderDetail> response) {
                if (response.isSuccessful()){
                    OrderDetail.DataBean rowsBean = response.body().getData();

                    Glide.with(OrderDetailActivity.this)
                            .load(Constant.BASE_URL2 + rowsBean.getImgUrl())
                            .into(im);
                    name.setText(rowsBean.getName());
                    star.setRating((float) rowsBean.getScore());

                    tag1.setText(rowsBean.getIntroduction());
                    tag2.setText("本月销量："+rowsBean.getSaleQuantity());
                    tag3.setText("3小时销量："+rowsBean.getSaleNum3hour());
                    tag4.setText("人均消费："+rowsBean.getAvgCost());
                    tag5.setText("地址："+rowsBean.getAddress());
                }
            }
        });


    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected String getActionBarTitle() {
        return null;
    }
}